package ee.maoinvest.backend.util;

import java.sql.Connection;
import java.sql.SQLException;

import org.apache.log4j.Logger;

public class TransactionControllHelper 
{
	private static Logger logger = Logger.getLogger(TransactionControllHelper.class);
	
	public static void setAutoCommitToFalse(Connection dbConnection)
	{
		try 
		{
			dbConnection.setAutoCommit(false);
			logger.info("Autocommit is now set to false");
		} 
		catch (SQLException e) 
		{
			logger.error(e.getMessage());
		}
	}
	
	
	public static void setAutoCommitToTrue(Connection dbConnection)
	{
		try 
		{
			dbConnection.setAutoCommit(true);
			logger.info("Autocommit is now set to true");
		} 
		catch (SQLException e) 
		{
			logger.error(e.getMessage());
		}
	}
	
	
	public static void rollBackATransaction(Connection dbConnection)
	{
		try 
		{
			dbConnection.rollback();
			logger.info("Rollback has been done!");
		} 
		catch (SQLException e) 
		{
			e.printStackTrace();
		}
	}
}
